Cluster Decision Resource Generator

The cluster decision resource generates a list of Argo CD clusters. This is done using duck-typing, which does not require knowledge of the full shape of the referenced kubernetes resource. The following is an example of a cluster-decision-resource-based ApplicationSet generator:

  1. apiVersion: argoproj.io/v1alpha1
  2. kind: ApplicationSet
  3. metadata:
  4. name: guestbook
  5. namespace: argocd
  6. spec:
  7. generators:
  8. - clusterDecisionResource:
  9. # ConfigMap with GVK information for the duck type resource
  10. configMapRef: my-configmap
  11. name: quak # Choose either "name" of the resource or "labelSelector"
  12. labelSelector:
  13. matchLabels: # OPTIONAL
  14. duck: spotted
  15. matchExpressions: # OPTIONAL
  16. - key: duck
  17. operator: In
  18. values:
  19. - "spotted"
  20. - "canvasback"
  21. # OPTIONAL: Checks for changes every 60sec (default 3min)
  22. requeueAfterSeconds: 60
  23. template:
  24. metadata:
  25. name: '{{name}}-guestbook'
  26. spec:
  27. project: "default"
  28. source:
  29. repoURL: https://github.com/argoproj/argocd-example-apps/
  30. targetRevision: HEAD
  31. path: guestbook
  32. destination:
  33. server: '{{clusterName}}' # 'server' field of the secret
  34. namespace: guestbook

The quak resource, referenced by the ApplicationSet clusterDecisionResource generator:

  1. apiVersion: mallard.io/v1beta1
  2. kind: Duck
  3. metadata:
  4. name: quak
  5. spec: {}
  6. status:
  7. # Duck-typing ignores all other aspects of the resource except
  8. # the "decisions" list
  9. decisions:
  10. - clusterName: cluster-01
  11. - clusterName: cluster-02

The ApplicationSet resource references a ConfigMap that defines the resource to be used in this duck-typing. Only one ConfigMap is required per ArgoCD instance, to identify a resource. You can support multiple resource types by creating a ConfigMap for each.

  1. apiVersion: v1
  2. kind: ConfigMap
  3. metadata:
  4. name: my-configmap
  5. data:
  6. # apiVersion of the target resource
  7. apiVersion: mallard.io/v1beta1
  8. # kind of the target resource
  9. kind: ducks
  10. # status key name that holds the list of Argo CD clusters
  11. statusListKey: decisions
  12. # The key in the status list whose value is the cluster name found in Argo CD
  13. matchKey: clusterName

(The full example can be found here.)

This example leverages the cluster management capabilities of the open-cluster-management.io community. By creating a ConfigMap with the GVK for the open-cluster-management.io Placement rule, your ApplicationSet can provision to different clusters in a number of novel ways. One example is to have the ApplicationSet maintain only two Argo CD Applications across 3 or more clusters. Then as maintenance or outages occur, the ApplicationSet will always maintain two Applications, moving the application to available clusters under the Placement rule’s direction.

How it works

The ApplicationSet needs to be created in the Argo CD namespace, placing the ConfigMap in the same namespace allows the ClusterDecisionResource generator to read it. The ConfigMap stores the GVK information as well as the status key definitions. In the open-cluster-management example, the ApplicationSet generator will read the kind placementrules with an apiVersion of apps.open-cluster-management.io/v1. It will attempt to extract the list of clusters from the key decisions. It then validates the actual cluster name as defined in Argo CD against the value from the key clusterName in each of the elements in the list.

The ClusterDecisionResource generator passes the ‘name’, ‘server’ and any other key/value in the duck-type resource’s status list as parameters into the ApplicationSet template. In this example, the decision array contained an additional key clusterName, which is now available to the ApplicationSet template.

Clusters listed as Status.Decisions must be predefined in Argo CD

The cluster names listed in the Status.Decisions must be defined within Argo CD, in order to generate applications for these values. The ApplicationSet controller does not create clusters within Argo CD.

The Default Cluster list key is clusters.